<?php
	// CLASSE DA BRODERAGEM ------ ESCRITA POR VENI
class Paginacao {
    var $not_query;
	var $reg_per_pag;
	var $reg_pag;
	
	function Paginacao($rpp,$rp){
		$this->not_query = new Persist;
		$this->reg_per_pag = $rpp;
		$this->reg_pag = $rp;
	}
	
	function maxPage($q){
		
		$max_reg = 0;
		$this->not_query->sql = $q;
	
		$max_reg = $this->not_query->ler();
		
		return ceil($max_reg / $this->reg_per_pag);
	}
	
	function montaQuery($q,$pagina){
		$limit = ($pagina * $this->reg_per_pag)-$this->reg_per_pag;
		return $q . " LIMIT " .  $limit . " , " . $this->reg_per_pag;
	}
	
	function montaPaginacao($q,$url,$pagina){
		$html = "<span class='ui-state-default ui-corner-all ui-icon-triangle-1-e' style='color:#6699FF;cursor:pointer' onclick=carregaBusca('$url&pagina=1','telas')><b> Primeira</b> </span>&nbsp;&nbsp;";
		
		$aux = 0;
		
		while( (($pagina - $this->reg_pag)+$aux) < 1)
			$aux++;
		
		for($reg = (($pagina - $this->reg_pag)+$aux) ; $reg <= (($pagina+$this->reg_pag) < $this->maxPage($q) ? $pagina+$this->reg_pag : $this->maxPage($q) ); $reg++){
			if($pagina == $reg)
				$html .= "<b >$reg</b>&nbsp;&nbsp;";
			else
				$html .= "<span class='ui-state-default ui-corner-all' style='text-decoration:none;color:#6699FF;cursor:pointer'  onclick=carregaBusca('$url&pagina=$reg','telas') ><b> $reg</b></span>&nbsp;&nbsp; ";
		}
		
		
		$html .= "<span class='ui-state-default ui-corner-all ui-icon-triangle-1-e' style='text-decoration:none;color:#6699FF;cursor:pointer' onclick=carregaBusca('$url&pagina=".$this->maxPage($q)."','telas')><b>Ultimo </b> </span>&nbsp;&nbsp;";
		
		return $html;
	}
	
	
}

?>